﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MacViet.DataBaseAPI;
using System.Data.SqlClient;

public partial class Control_EmployeesList : System.Web.UI.UserControl
{
    private int acc_id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
       
            
        
            if (!IsPostBack)
            {
                if (Session["ACC_ID"] != null)
                {
                    loadGridView();                    
                }
                else
                {
                    Response.Redirect("AccountLogin.aspx");
                }
                
            }
        
   
    }

    private void loadGridView()
    {
        EMPLOYEESDataAPI api = new EMPLOYEESDataAPI();
        acc_id = int.Parse(Session["ACC_ID"].ToString());
        grvShow.DataSource = api.getByACC_ID(acc_id);
        grvShow.DataBind();   
        
    }
    //protected void DeleteBtn_Click(object sender, EventArgs e)
    //{
    //    acc_id = int.Parse(Session["ACC_ID"].ToString());
    //    for (int i = 0; i < grvShow.Rows.Count; i++)
    //    {
    //        string id = string.Empty;
    //        GridViewRow rows=grvShow.Rows[i];
    //        bool chekBox = (rows.FindControl("chkSelect") as CheckBox).Checked;
    //        if (chekBox)
    //        {
    //            if (id == string.Empty)
    //            {
    //                id = grvShow.DataKeys[i].Value.ToString();
    //                EMPLOYEESDataAPI api = new EMPLOYEESDataAPI();
    //                bool result = api.deleteEMPLOYEES(int.Parse(id));
    //                if (result == false)
    //                {
    //                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please delete all records of this employee....');", true);
    //                    grvShow.DataSource = api.getByACC_ID(acc_id);
    //                    grvShow.DataBind();
    //                }
    //                else
    //                {
    //                    lblMessage.Text = "Delete Successfully!!!";
    //                }
    //            }
    //            else
    //                id += grvShow.DataKeys[i].Value.ToString() + ",";
    //        }
    //    }       

    //}

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_EmployeeAdd.aspx");
    }
   
    protected void grvShow_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.className='highlight'");
            e.Row.Attributes.Add("onmouseout", "this.className='normal'");
        }
    }
}
